<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Burger.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <a href="index.source.html" class="el_package">praktikum</a> &gt; <span class="el_source">Burger.java</span></div><h1>Burger.java</h1><pre class="source lang-java linenums">package praktikum;

import java.util.ArrayList;
import java.util.List;

/**
 * Модель бургера.
 * Бургер состоит из булочек и ингредиентов (начинка или соус).
 * Ингредиенты можно перемещать и удалять.
 * Можно распечать чек с информацией о бургере.
 */
<span class="fc" id="L12">public class Burger {</span>

    public Bun bun;
<span class="fc" id="L15">    public List&lt;Ingredient&gt; ingredients = new ArrayList&lt;&gt;();</span>

    public void setBuns(Bun bun) {
<span class="fc" id="L18">        this.bun = bun;</span>
<span class="fc" id="L19">    }</span>

    public void addIngredient(Ingredient ingredient) {
<span class="fc" id="L22">        ingredients.add(ingredient);</span>
<span class="fc" id="L23">    }</span>

    public void removeIngredient(int index) {
<span class="fc" id="L26">        ingredients.remove(index);</span>
<span class="fc" id="L27">    }</span>

    public void moveIngredient(int index, int newIndex) {
<span class="fc" id="L30">        ingredients.add(newIndex, ingredients.remove(index));</span>
<span class="fc" id="L31">    }</span>

    public float getPrice() {
<span class="fc" id="L34">        float price = bun.getPrice() * 2;</span>

<span class="fc bfc" id="L36" title="All 2 branches covered.">        for (Ingredient ingredient : ingredients) {</span>
<span class="fc" id="L37">            price += ingredient.getPrice();</span>
<span class="fc" id="L38">        }</span>

<span class="fc" id="L40">        return price;</span>
    }

    public String getReceipt() {
<span class="fc" id="L44">        StringBuilder receipt = new StringBuilder(String.format(&quot;(==== %s ====)%n&quot;, bun.getName()));</span>

<span class="fc bfc" id="L46" title="All 2 branches covered.">        for (Ingredient ingredient : ingredients) {</span>
<span class="fc" id="L47">            receipt.append(String.format(&quot;= %s %s =%n&quot;, ingredient.getType().toString().toLowerCase(),</span>
<span class="fc" id="L48">                    ingredient.getName()));</span>
<span class="fc" id="L49">        }</span>

<span class="fc" id="L51">        receipt.append(String.format(&quot;(==== %s ====)%n&quot;, bun.getName()));</span>
<span class="fc" id="L52">        receipt.append(String.format(&quot;%nPrice: %f%n&quot;, getPrice()));</span>

<span class="fc" id="L54">        return receipt.toString();</span>
    }

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>